gold 12Dec2018: This page is under development. Comments are welcome, but please load any comments in the comments section at the bottom of the page. Please include your wiki MONIKER and date in your comment with the same courtesy that I will give you. Aside from your courtesy, your wiki MONIKER and date as a signature and minimal good faith of any Internet post are the rules of this TCL-WIKI. Its very hard to reply reasonably without some background of the correspondent on his WIKI bio page.
gold Started roughly 2011-05-18. Here is a TCL script on Call Procedure Fortran like. A call statement has some advantages in both the Fortran and TCL languages. In some variants/versions of Fortran, the call statement is used to control program flow and invoke subroutines. For example, a Call Exit could be used to halt the program execution. A similar procedure for Call Return is also possible in a TCL subroutine. For math in TCL, a call procedure or other math procedures can be developed that do require brackets. A call procedure is a possible "sugar" concept for many TCL core commands and subroutines.
gold 10Oct2020. This "sugar" concept was initially developed in upvar sugar, Salt and Sugar, Math sugar, Radical Language Modification, and Functional Programming by RS, LV, RLE, and others on the wiki. The call statement may be used to organize programs into a list of subroutines and to exit the program. In the early days of programming, exiting a program was not a trivial function. Usually the Fortran dogma was a conditional STOP or END statement at the end of a punched card deck or subroutine deck, preventing endless loops. In Fortran_4 subroutines some multiple termination statements like STOP;END; and RETURN;STOP;END; were not uncommon. A statement like "call exit" seemed pretty swank to beginner Fortran programmers. Below, a generic TCL program passes control through various dummy procedures. Some puts bye and math statements are used to show control is passing through the procedures.
gold 10Oct2020. A list of "call subroutines" is a simple way to organize a main program with successive subroutines, although in TCL the subroutine procedures usually have to be defined first at the head of the main deck. An alternate method is to wrap the subroutine list into a collective proc. The collective proc can be placed at the head and makes one's organized thoughts more apparent to the reader. The "easy eye" console was used as a testbed for one-liner programs in TCL on Windows 10. Essentially, the experimental code is translating Fortran and Quickbasic control-flow statements into one-liner programs. The "easy eye" console has large black type on green background for bad eyes. It may include an extra Self_help button under the normal Help button of console display.
gold 10Oct2020. A console program was modified for experiments on Natural Language, if the King's English is a natural language. The console program was based on the antique program King Hamurabi.bas, ref Game kingdom of strategy. The idea was a limited set of input commands in the King's English, SVO as subject verb object. The initial commands in the computer game were <king buy 30 grain> or <king sell 20 land>, lower case. English is an ambiguous language in that terms can either be used as verbs or objects. For example, the above term exit could either be used as a verb, noun, or adjective, as in "please exit though the exit under the exit sign".
Timing call subroutines indicates fairly high overhead of about 6 microseconds per iteration. Proc C is using set as substitution, fairly fast. Proc Call math is fairly slow compared to math ops and expr.
gold 12Dec2018. I have been informed that an advanced TCL user has added and checked this Call Exit subroutine into his homebrew TCL interpreter on his local copy of TCL on a PC system. I have added this subroutine code to my local TCL copy. Meaning the subroutine code may be added to source code library in TCLLIB. But I am not sure these subroutines add much to what is already available on TCL.
Using a list of successive "call subroutines".
# pseudocode console show proc call {args} {uplevel catch [list $args]} call initilize ;# list variables call subroutine1 call subroutine2 call subroutine3 call subroutine4 call exit ;# stop statement proc initilize return proc subroutine1 return proc subroutine2 return proc subroutine3 return proc subroutine4 call math sin(.5) return # ... pseudocode:
# autoindent syntax from ased editor. # call procedure like fortran example # written on Windows XP on eTCL # working under TCL version 8.5.6 and eTCL 1.0.1 package require Tk console show proc call {args} {uplevel catch [list $args]} proc math { args } { set tcl_precision 17; puts [ expr [ expr { $args } ] ] } proc list_subroutines { variable } { call initilize ;# list variables call subroutine1 1 ;# set up inputs call subroutine2 2 ;# calculations call subroutine3 3 ;# error checks call subroutine4 4 ;# print results call math sin (.5) if { 1 == 1 } { puts "bye bye" }} proc initilize {aa} { puts "subroutine initilize active" return } proc subroutine1 {aa} { puts "subroutine 1 active" return } proc subroutine2 {aa} { puts "subroutine 2 active" return } proc subroutine3 {aa} { puts "subroutine 3 active" return } proc subroutine4 {aa} { puts "subroutine 4 active" call math sin (.5) if { 1 == 1 } { puts "bye" } if { 1 == 2 } { call exit } return } call list_subroutines 1 #end of deck
# console output 0.479425538604203 bye 0.479425538604203 bye bye
console show proc pie {} {expr acos(-1)} proc writer {args } { puts $args } proc call {args} {uplevel catch [list $args]} call writer "jack" "&" "jill" call writer jack & jill went up the hill with [pie]
% console output jack & jill jack & jill went up the hill with 3.141592653589793
console show proc pie {} {expr acos(-1)} proc writer {args } { puts $args } proc math { args } { set tcl_precision 17; puts [ expr [ expr { $args } ] ] } proc mathx { args } { set tcl_precision 17; return [ expr [ expr { $args } ] ] } proc call {args} {uplevel catch [list $args]} call math 5 + 5 call math 5 + 5 call math sin (.5) set ccc [ mathx sin (.5) ] puts " value $ccc "
% console output 10 10 0.479425538604203 value 0.479425538604203
#ref. func proc from https://wiki.tcl-lang.org/14006 #Tacit programming #Tacit programming.mht,RS console show proc pie {} {expr acos(-1)} set aa 1 proc call {args} {uplevel catch [list $args]} proc math { args } { set tcl_precision 17; puts [ expr [ expr { $args } ] ] } proc func {name argl body} {proc $name $argl [list expr $body]} ;# RS func atand aa (180./[pie])*atan($aa) ;# RS puts " [atand 1. ] " console show proc pie {} {expr acos(-1)} set aa 1 proc call {args} {uplevel catch [list $args]} proc math { args } { set tcl_precision 17; puts [ expr [ expr { $args } ] ] } proc func {name argl body} {proc $name $argl [list expr $body]} ;# RS func atand aa (180./[pie])*atan($aa) set aaa [ atand 1. ] puts $aaa #end of deck
output from console with program loaded,
call subroutine2 call ;# returns subroutine 2 active6 call ;# returns 0 call call ;# returns 0 call call call ;# returns 0 # trivial as zero list, but no errors from multiple calls.
Timing call subroutines indicates fairly high overhead of about 6 microseconds per iteration. Proc C is using set as substitution, fairly fast. Call math is fairly slow compared to math ops and expr.
time { call + 1 2 3 } 5000 #; returns 6.1238 microseconds per iteration time { + 1 2 3 } 5000 #; returns 0.1682 microseconds per iteration time { call puts 1 2 3 } 5000 #; returns 7.523 microseconds per iteration time { call call call } 5000 ;# returns 12.3354 microseconds per iteration time { ::math::numtheory::call + 1 2 3 } 5000 ;# returns 5.616 microseconds per iteration # locating call subroutine inside local TCLLIB saves about 10 percent time here time { * 5 5 0.017455064928217585 } 5000 ;# returns 0.1928 microseconds per iteration in math ops time { expr { 5 * 5 * 0.017455064928217585 } } 5000 ;# returns 0.1036 microseconds per iteration in expr # math ops and expr method fast compared to call math time { call math 5 * 5 * 0.017455064928217585 } 5000 ;# returns 20.2576 microseconds per iteration time { * 5 5 0.017455064928217585 } 5000 ;# returns 0.1912 microseconds per iteration time { C 1 3 4 5 6 7 8 } 5000 ;# returns 0.5466 microseconds per iteration # proc C is using set as substitution, fairly fast
# pretty print from autoindent and ased editor # call procedure like fortran V2 # easy eye console V3, large black type on green # used as testbed for one liners programs # written on Windows 10 on TCL # working under TCL version 8.6 # base one liner derived from # gold on TCL WIKI , 10Sep2020 # includes Self_help under Help # tap of console display package require Tk package require math::numtheory package require math::constants package require math::trig package require math namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory math::trig math::constants } set tclprecision 17 proc call {args} {uplevel catch [list $args]} proc math { args } { set tcl_precision 17; puts [ expr [ expr { $args } ] ] } # successive subroutines of main listed in one liner proc # foreach list organizes control to pass through numbered subroutines proc list_subroutines { variable } {foreach item {1 2 3 4 } {subroutine$item $item }} # translating Fortran and Quickbasic control flow statements # into one liners programs proc stop {} { return } proc end {} { exit } proc pause {} { wait .00010} proc C {args} { set C # } proc REM {args} { set REM # } ;# attack of bots from Quickbasic proc write {args} { puts $args } proc print {args} { puts $args } ;# attack of bots from Quickbasic proc SUBROUTINE {args} { proc $args } proc SUB {args} { proc $args } ;# attack of bots from Quickbasic proc initilize {aa} { puts "subroutine initilize active" call return } proc subroutine1 {aa} { puts "subroutine 1 active" puts " fired subroutine $aa " call return } proc subroutine2 {aa} { puts "subroutine 2 active" puts " fired subroutine $aa " call return } proc subroutine3 {aa} { puts "subroutine 3 active" puts " fired subroutine $aa " call return } proc subroutine4 {aa} { puts "subroutine 4 active" call math sin (.5) write " fired subroutine $aa " if { 1 == 1 } { puts "bye" } if { 1 == 2 } { call exit } print " *******************************" REM testing Quickbasic control words too print " attack of bots from Quickbasic " print " testing Quickbasic control words too " print " Quickbasic bots now in retreat " print " *******************************" # swapping C args for # comments C messege to terminal, operator stop or proceed C pause C redundant subroutine terminators C return control from subroutine to main program return C stop means stop execution to subprogram or main program stop C end means end execution to subprogram or main program end } # # successive subroutines of main listed in one liner proc above list_subroutines 1 call math sin (.5) if { 1 == 1 } { puts "bye bye" } console show console eval {.console config -bg palegreen} # normally use extra big font 40 and but # big fonts 30 or 40, rectangle 40x20 do not display well on wiki console eval {.console config -font {fixed 20 bold}} console eval {wm geometry . 20x20} console eval {wm title . " Call procedure like Fortran V2, screen grab and paste from console 2 to texteditor"} console eval {. configure -background orange -highlightcolor brown -relief raised -border 30} console eval { proc self_helpx {} { set msg "in TCL, large black type on green from TCL, self help listing Conventional text editor formulas grabbed from internet screens can be pasted into green console # Call procedure like Fortran V2 # testbed for one liner programs # loading math ops, TCLLIB components # suggest maintain dead spaces and air gaps near expr, brackets, etc # Note spaces near expr statement must be maintained # or program deck will not work. # blanks _b must be there # pretty print from autoindent and ased editor # call procedure like fortran V2 # easy eye console V3, large black type on green # used as testbed for one liners programs # written on Windows 10 on TCL # working under TCL version 8.6 # control passes in sucesssion through 4 subroutines # example >> math .5 # example >> call math .5 # example >> call exit # example >> math 1*2*3*4*5*6*7*8*9 # example math 5 * 5 * [tand 1.] # gold on TCL Club , 10Sep2020 " tk_messageBox -title "self_helpxx" -message $msg } } console eval {.menubar.help add command -label Self_help -command self_helpx } puts "******************************************************* " puts " console session >> loads Fortran like call into console " puts " console session >> self_help specific loaded in console help " puts " creating new commands inside TCL deck " puts " example >> math .5 " puts " example >> call math .5 " puts " example >> call exit " puts " example >> math 5 * 5 * [tand 1.] " puts " ******************************************************* " # End of deck
Please place any comments here with your wiki MONIKER and date, Thanks.gold12Dec2018
gold 9/27/2021. Switched some comment signs ;# to #. This a big file. Check earlier editions, if not compatible. Maybe obvious, but this page was written on Windows10 Tcl ports including ActiveTCL. I assume that the reader can cut and paste on screen, what the reader needs, and tootle on to his own project and own contribution pages to the TCL Wiki.
Category Numerical Analysis | Category Toys | Category Calculator | Category Mathematics | Category Example | Toys and Games | Category Games | Category Application | Category GUI |
Category Development | Category Concept | Category Algorithm | Category Language | programming language | Category Fortran | Natural Languages |